<?php 
header('Content-Type: text/html; charset=UTF-8');?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ĐIỂM HỌC KỲ</title>
</head>

<?php 

mysql_query("SET NAMES 'utf8'");
require ("sql.php");
?>
<body>
<form id='form1' name='form1' method="post" action="diem.php">
Mã học sinh: <input type="text" name="m_hs" style="width:100px;"/>
Mã học kì: <input type="text" name="m_hk" style="width:100px;"/>
Tên môn học: <input type="text" name="ten_mh" style="width:100px;"/>
<input type="submit" value="Xem điểm" />
<a style="float:right" href="index.php">Quay lại trang chủ</a>
</form>

<hr/>
<?php
if(($_POST["m_hs"]!=null)&&($_POST["m_hk"]!=null))
{
$m_hk = $_POST["m_hk"];
$m_hs = $_POST["m_hs"];
$ten_mh = $_POST["m_mh"];
$query="select hs.m_hs,ten,ten_mh,diem_mieng,diem_15p,diem_bs1,diem_bs2,diem_1tiet1,diem_1tiet2,diem_thi from mon,hs,diem where mon.m_mh=diem.m_mh and diem.m_hs=hs.m_hs and diem.m_hk='{$m_hk}'and diem.m_hs='{$m_hs}' and ten_mh='{$ten_mh}'";
$cursor=mysql_query($query);
if(!empty($cursor))
{
	$row=mysql_fetch_row($cursor);
}
else
{echo mysql_error();die();}

echo"Học sinh: $row[1]<br/>";
echo"Mã số hs: $row[0]";

  echo"<table border='2' align='center' cellpadding='1' cellspacing='5'>";
    echo"<tr>";
		echo"<td width='80'>Tên môn</td>";
		echo"<td width='80'>Điểm miệng</td>";
		echo"<td width='80'>Điểm 15 phút</td>";
		echo"<td width='80'>Điểm 3</td>";
		echo"<td width='80'>Điểm 4</td>";
		echo"<td width='80'>Điểm 1 tiết 1</td>";
		echo"<td width='80'>Điểm 1 tiết 2</td>";
		echo"<td width='80'>Điểm thi</td>";
		echo"<td width='80'>Điểm tổng kết</td>";
	echo"</tr>";
	echo"<tr>";
		echo"<td width='40'>$row[2]</td>";
		echo"<td width='40'>$row[3]</td>";
		echo"<td width='40'>$row[4]</td>";
		echo"<td width='40'>$row[5]</td>";
		echo"<td width='40'>$row[6]</td>";
		echo"<td width='40'>$row[7]</td>";
		echo"<td width='40'>$row[8]</td>";
		echo"<td width='40'>$row[9]</td>";
		$diem_tk=($row[3]+$row[4]+$row[5]+$row[6]+($row[7]+$row[8])*2+$row[9]*3)/11;
		echo"<td width='40'>$diem_tk</td>";
	echo"</tr>";
	echo"  </table>";
if($diem_tk<3)
{echo"Xếp loại học kỳ: kém";}
if(($diem_tk>=3)&&($diem_tk<5))
{echo"Xếp loại học kỳ: yếu";}
if(($diem_tk>=5)&&($diem_tk<6.5))
{echo"Xếp loại học kỳ: trung bình";}
if(($diem_tk>=6.5)&&($diem_tk<8))
{echo"Xếp loại học kỳ: khá";}
if($diem_tk>=8)
{echo"Xếp loại học kỳ: giỏi";}
}
?>

</body>
</html>